//----------------------------------------------------------------
//Tên Class: Cls_ThongTinGia_ChiTiet
//Người thực hiện: NhatTHM
//Website: www.nhatthanh.net
//-----------------------------------------------------------------
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
namespace Library.Business {
	public partial class Cls_ThongTinGia_ChiTiet
	{
		protected string sSQL;
		//Tham số cho Procudure
		#region Tham số cho Procudure
		protected const string st_ThongTinGia_ChiTiet_Insert = "st_ThongTinGia_ChiTiet_Insert";
		protected const string st_ThongTinGia_ChiTiet_Update = "st_ThongTinGia_ChiTiet_Update";
		protected const string st_ThongTinGia_ChiTiet_Update_ALL = "st_ThongTinGia_ChiTiet_Update_ALL";
		protected const string st_ThongTinGia_ChiTiet_Update_Hidden = "st_ThongTinGia_ChiTiet_Update_Hidden";
		protected const string st_ThongTinGia_ChiTiet_Delete = "st_ThongTinGia_ChiTiet_Delete";
		protected const string st_ThongTinGia_ChiTiet_SelectAll = "st_ThongTinGia_ChiTiet_SelectAll";
		protected const string st_ThongTinGia_ChiTiet_SelectAll_Key = "st_ThongTinGia_ChiTiet_SelectAll_Key";
		protected const string st_ThongTinGia_ChiTiet_SelectByID = "st_ThongTinGia_ChiTiet_SelectByID";
		protected const string st_ThongTinGia_ChiTiet_SelectByID_Stand = "st_ThongTinGia_ChiTiet_SelectByID_Stand";
		protected const string TABLE_NAME = "tbThongTinGia_ChiTiet";
		#endregion Tham số cho Procudure
		//Các tên filed của table.
		#region Các tên filed của table.
		public const string fn_ID = "ID";
		public const int len_ID = 4;
		public const string fn_ID_ThongTinGia = "ID_ThongTinGia";
		public const int len_ID_ThongTinGia = 4;
		public const string fn_ID_LoaiHinhDoanhNghiep = "ID_LoaiHinhDoanhNghiep";
		public const int len_ID_LoaiHinhDoanhNghiep = 30;
		public const string fn_DonGia = "DonGia";
		public const int len_DonGia = 8;
		public const string fn_ThueGTGT = "ThueGTGT";
		public const int len_ThueGTGT = 8;
		public const string fn_Thue_1 = "Thue_1";
		public const int len_Thue_1 = 8;
		public const string fn_Thue_2 = "Thue_2";
		public const int len_Thue_2 = 8;
		public const string fn_Thue_3 = "Thue_3";
		public const int len_Thue_3 = 8;
		public const string fn_Phi_1 = "Phi_1";
		public const int len_Phi_1 = 8;
		public const string fn_Phi_2 = "Phi_2";
		public const int len_Phi_2 = 8;
		public const string fn_Phi_3 = "Phi_3";
		public const int len_Phi_3 = 8;
		public const string fn_Hidden = "Hidden";
		public const int len_Hidden = 1;
		//Các filed của table.
		private int _iD_find;
		private int _iD;
		private int _iD_ThongTinGia;
		private string _iD_LoaiHinhDoanhNghiep;
		private double _donGia;
		private double _thueGTGT;
		private double _thue_1;
		private double _thue_2;
		private double _thue_3;
		private double _phi_1;
		private double _phi_2;
		private double _phi_3;
		private bool _hidden;
		#endregion Các tên filed của table.
		#region Các phương thức cho table.
		//Thuộc tính ID_find
		public int ID_find
		{
			get{return this._iD_find;}
			set{this._iD_find = value;}
		}
		//Thuộc tính ID
		public int ID
		{
			get{return this._iD;}
			set{this._iD = value;}
		}
		//Thuộc tính ID_ThongTinGia
		public int ID_ThongTinGia
		{
			get{return this._iD_ThongTinGia;}
			set{this._iD_ThongTinGia = value;}
		}
		//Thuộc tính ID_LoaiHinhDoanhNghiep
		public string ID_LoaiHinhDoanhNghiep
		{
			get{return this._iD_LoaiHinhDoanhNghiep;}
			set{this._iD_LoaiHinhDoanhNghiep = value;}
		}
		//Thuộc tính DonGia
		public double DonGia
		{
			get{return this._donGia;}
			set{this._donGia = value;}
		}
		//Thuộc tính ThueGTGT
		public double ThueGTGT
		{
			get{return this._thueGTGT;}
			set{this._thueGTGT = value;}
		}
		//Thuộc tính Thue_1
		public double Thue_1
		{
			get{return this._thue_1;}
			set{this._thue_1 = value;}
		}
		//Thuộc tính Thue_2
		public double Thue_2
		{
			get{return this._thue_2;}
			set{this._thue_2 = value;}
		}
		//Thuộc tính Thue_3
		public double Thue_3
		{
			get{return this._thue_3;}
			set{this._thue_3 = value;}
		}
		//Thuộc tính Phi_1
		public double Phi_1
		{
			get{return this._phi_1;}
			set{this._phi_1 = value;}
		}
		//Thuộc tính Phi_2
		public double Phi_2
		{
			get{return this._phi_2;}
			set{this._phi_2 = value;}
		}
		//Thuộc tính Phi_3
		public double Phi_3
		{
			get{return this._phi_3;}
			set{this._phi_3 = value;}
		}
		//Thuộc tính Hidden
		public bool Hidden
		{
			get{return this._hidden;}
			set{this._hidden = value;}
		}
		#endregion Các phương thức cho table.
		/// <summary>
		/// Hàm khởi tạo không có tham số.
		/// </summary>
		public Cls_ThongTinGia_ChiTiet()
		{
		}

		/// <summary>
		/// Hàm khởi tạo có  tham số.
		/// </summary>
		public Cls_ThongTinGia_ChiTiet(int id_thongtingia, string id_loaihinhdoanhnghiep, double dongia, double thuegtgt, double thue_1, double thue_2, double thue_3, double phi_1, double phi_2, double phi_3, bool hidden)
		{
			this._iD_ThongTinGia = id_thongtingia;
			this._iD_LoaiHinhDoanhNghiep = id_loaihinhdoanhnghiep;
			this._donGia = dongia;
			this._thueGTGT = thuegtgt;
			this._thue_1 = thue_1;
			this._thue_2 = thue_2;
			this._thue_3 = thue_3;
			this._phi_1 = phi_1;
			this._phi_2 = phi_2;
			this._phi_3 = phi_3;
			this._hidden = hidden;
		}
        /// <summary>
        /// Đếm tổng số bảng ghi.
        /// </summary>
        /// <returns></returns>
        public static int countRows(bool Hidden)
        {
            SqlConnection con = new AccessDB().get_Conn();
            SqlCommand sqlComm = new SqlCommand("st_ThongTinGia_ChiTiet_Count", con);
            sqlComm.CommandType = CommandType.StoredProcedure;
            sqlComm.Parameters.Add("@Hidden", SqlDbType.Bit).Value = Hidden;
            try
            {
                con.Open();
                int intResult= (int)sqlComm.ExecuteScalar();
                return intResult;
            }
            catch (SqlException ex)
            {
                new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
                throw ex;
            }
            finally
            {
                if (sqlComm != null) sqlComm.Dispose();
                if (con != null) con.Close();
            }
        }
        /// <summary>
        /// Xác định Khóa chính có tồn tại dữ liệu.
        /// </summary>
        /// <returns>Truy: Có; False: Không</returns>
        public bool Exits_Key()
        {
            SqlConnection con = new AccessDB().get_Conn();
            SqlCommand sqlComm = new SqlCommand("st_ThongTinGia_ChiTiet_Count_Key", con);
            sqlComm.CommandType = CommandType.StoredProcedure;
            try
            {
                sqlComm.Parameters.Add("@ID", SqlDbType.Int).Value = ID;
                con.Open();
                if (((int)sqlComm.ExecuteScalar()) == 1) return true;
                else return false;
            }
            catch (SqlException ex)
            {
                new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
                throw ex;
                return false;
            }
            finally
            {
                if (sqlComm != null) sqlComm.Dispose();
                if (con != null) con.Close();
            }
        }
        /// <summary>
        /// Xác định Khóa chính có tồn tại dữ liệu.
        /// </summary>
        /// <returns>Truy: Có; False: Không</returns>
        public static bool Exits_Key(int key_ID)
        {
            SqlConnection con = new AccessDB().get_Conn();
            SqlCommand sqlComm = new SqlCommand("st_ThongTinGia_ChiTiet_Count_Key", con);
            sqlComm.CommandType = CommandType.StoredProcedure;
            try
            {
                sqlComm.Parameters.Add("@ID", SqlDbType.Int).Value = key_ID;
                con.Open();
                if (((int)sqlComm.ExecuteScalar()) == 1) return true;
                else return false;
            }
            catch (SqlException ex)
            {
                new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
                throw ex;
                return false;
            }
            finally
            {
                if (sqlComm != null) sqlComm.Dispose();
                if (con != null) con.Close();
            }
        }
        /// <summary>
        /// Get max ID auto.
        /// </summary>
        /// <returns></returns>
        public static int getMaxIdAuto()
        {
            SqlConnection con = new AccessDB().get_Conn();
        	string sSQL = "SELECT MAX(ID) FROM tbThongTinGia_ChiTiet";

            SqlCommand sqlComm = new SqlCommand(sSQL, con);
            sqlComm.CommandType = CommandType.Text;
            try
            {
                con.Open();
                return (int)sqlComm.ExecuteScalar();
            }
            catch (SqlException ex)
            {
                new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
                throw ex;
            }
            finally
            {
                if (sqlComm != null) sqlComm.Dispose();
                if (con != null) con.Close();
            }
        }
		/// <summary>
		/// Get DataTable NULL với table class.
		/// </summary>
		/// <returns></returns>
		public static DataTable getDataTable_NULL()
		{
		    SqlConnection con = new AccessDB().get_Conn();
			SqlCommand sqlComm = new SqlCommand("Select Top 0 * From tbThongTinGia_ChiTiet", con);
			sqlComm.CommandType = CommandType.Text;
			try
			{
				SqlDataAdapter sqlDTA = new SqlDataAdapter(sqlComm);
				DataTable dt = new DataTable();
		        con.Open();
				sqlDTA.Fill(dt);
				return dt;
			}
			catch (SqlException ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
		        throw ex;
			}
		    finally
		    {
		        if (sqlComm != null) sqlComm.Dispose();
		        if (con != null) con.Close();
		    }
		}

		/// <summary>
		/// Get DataTable với table class.
		/// </summary>
		/// <returns></returns>
		public static DataTable getDataTable_My_Key()
		{
		    SqlConnection con = new AccessDB().get_Conn();
			SqlCommand sqlComm = new SqlCommand(st_ThongTinGia_ChiTiet_SelectAll_Key, con);
			sqlComm.CommandType = CommandType.StoredProcedure;
			try
			{
				SqlDataAdapter sqlDTA = new SqlDataAdapter(sqlComm);
				DataTable dt = new DataTable();
		        con.Open();
				sqlDTA.Fill(dt);
				return dt;
			}
			catch (SqlException ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
		        throw ex;
			}
		    finally
		    {
		        if (sqlComm != null) sqlComm.Dispose();
		        if (con != null) con.Close();
		    }
		}

		/// <summary>
		/// Get DataTable với Where time.
		/// </summary>
		/// <param name="strWhere">Where get ucChonNgay t</param>
		/// <returns></returns>
		public static DataTable getDataTable_Time(string strWhere)
		{
			try
			{
				string sSQL = "SELECT * FROM tbThongTinGia_ChiTiet" + strWhere+" Order By DateCreate DESC,ID_SYS_Message_Warning Desc";
				return getDataTable_SQL_pro(sSQL);
			}
			catch (SqlException ex)
			{
				return null;
			}
		}

		/// <summary>
		/// Get DataTable với Where.
		/// </summary>
		/// <returns></returns>
		public static DataTable getDataTable_Where(string strWhere,string FieldSort)
		{
			try
			{
			    if (FieldSort.Trim().Length == 0) FieldSort = "";
			    else FieldSort = " Order By " + FieldSort;
			    //
			    if (strWhere.Trim().Length == 0) strWhere = "";
			    else strWhere = " WHERE " + strWhere;
				string sSQL = "SELECT * FROM tbThongTinGia_ChiTiet" + strWhere + FieldSort ;
				return getDataTable_SQL_pro(sSQL);
			}
			catch (SqlException ex)
			{
				return null;
			}
		}

		/// <summary>
		/// Get DataTable với table class.
		/// </summary>
		/// <param name="ID">ID</param>
		/// <returns></returns>
		public static DataTable getDataTable_SQL_pro(string sSQL)
		{
		    SqlConnection con = new AccessDB().get_Conn();
			SqlCommand sqlComm = new SqlCommand("st_processSQL",con);
			sqlComm.CommandType = CommandType.StoredProcedure;
			DataTable dt = new DataTable();
			try
			{
				sqlComm.Parameters.Add("@sSQL", SqlDbType.NVarChar).Value = sSQL;
				SqlDataAdapter sqlDTA = new SqlDataAdapter(sqlComm);
		        con.Open();
				sqlDTA.Fill(dt);
				return dt;
			}
			catch (SqlException ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, sSQL + " - " + ex.Message);
		        throw ex;
			}
            finally
            {
                if (dt != null) dt.Dispose();
                if (sqlComm != null) sqlComm.Dispose();
                if (con != null) con.Close();
            }
		}

		/// <summary>
		/// Get DataTable với table class.
		/// </summary>
		/// <param name="ID">ID</param>
		/// <returns></returns>
		public static DataTable getDataTable_My()
		{
		    SqlConnection con = new AccessDB().get_Conn();
			SqlCommand sqlComm = new SqlCommand(st_ThongTinGia_ChiTiet_SelectAll, con);
			sqlComm.CommandType = CommandType.StoredProcedure;
			SqlDataAdapter sqlDTA = new SqlDataAdapter(sqlComm);
		    DataTable dt = new DataTable();
			try
			{
		        con.Open();
				sqlDTA.Fill(dt);
				return dt;
			}
			catch (SqlException ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
		        throw ex;
			}
		    finally
		    {
		        if (dt != null) dt.Dispose();
		        if (sqlComm != null) sqlComm.Dispose();
		        if (con != null) con.Close();
		    }
		}

		/// <summary>
		/// Get DataTable với table class.
		/// </summary>
		/// <param name="ID">ID</param>
		/// <returns></returns>
		public static DataSet getDataSet_My()
		{
		    SqlConnection con = new AccessDB().get_Conn();
			SqlCommand sqlComm = new SqlCommand(st_ThongTinGia_ChiTiet_SelectAll, con);
			sqlComm.CommandType = CommandType.StoredProcedure;
			SqlDataAdapter sqlDTA = new SqlDataAdapter(sqlComm);
		    DataSet ds = new DataSet();
			try
			{
		        con.Open();
				sqlDTA.Fill(ds);
				return ds;
			}
			catch (SqlException ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
		        throw ex;
			}
		    finally
		    {
		        if (ds != null) ds.Dispose();
		        if (sqlComm != null) sqlComm.Dispose();
		        if (con != null) con.Close();
		    }
		}

		public static DataTable getDataTable_Hidden(bool Hidden)
		{
		    SqlConnection con = new AccessDB().get_Conn();
		    SqlCommand sqlComm = new SqlCommand("st_ThongTinGia_ChiTiet_SelectAll_Hidden", con);
		    sqlComm.CommandType = CommandType.StoredProcedure;
		    sqlComm.Parameters.Add("@Hidden", SqlDbType.Bit).Value = Hidden;

		    SqlDataAdapter sqlDTA = new SqlDataAdapter(sqlComm);
		    DataTable dt = new DataTable();
			try
			{
		        con.Open();
				sqlDTA.Fill(dt);
				return dt;
			}
			catch (SqlException ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
		        throw ex;
				return null;
			}
		    finally
		    {
		        if (sqlDTA != null) sqlDTA.Dispose();
		        if (dt != null) dt.Dispose();
		        if (sqlComm != null) sqlComm.Dispose();
		        if (con != null) con.Close();
		    }
		}

		public static DataSet getDataSet_Hidden(bool Hidden)
		{
		    SqlConnection con = new AccessDB().get_Conn();
		    SqlCommand sqlComm = new SqlCommand("st_ThongTinGia_ChiTiet_SelectAll_Hidden", con);
		    sqlComm.CommandType = CommandType.StoredProcedure;
		    sqlComm.Parameters.Add("@Hidden", SqlDbType.Bit).Value = Hidden;

		    SqlDataAdapter sqlDTA = new SqlDataAdapter(sqlComm);
		    DataSet ds = new DataSet();
			try
			{
		        con.Open();
				sqlDTA.Fill(ds);
				return ds;
			}
			catch (SqlException ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
		        throw ex;
			}
		    finally
		    {
		        if (sqlDTA != null) sqlDTA.Dispose();
		        if (ds != null) ds.Dispose();
		        if (sqlComm != null) sqlComm.Dispose();
		        if (con != null) con.Close();
		    }
		}

		/// <summary>
		/// Get DataTable với table class.
		/// </summary>
		/// <param name="ID">ID</param>
		/// <returns></returns>
		public static DataTable getDataTable_My(int key_ID)
		{
		    SqlConnection con = new AccessDB().get_Conn();
			SqlCommand sqlComm = new SqlCommand(st_ThongTinGia_ChiTiet_SelectByID, con);
			sqlComm.CommandType = CommandType.StoredProcedure;
			try
			{
		        con.Open();
				//
				sqlComm.Parameters.Add("@ID", SqlDbType.Int).Value = key_ID;
				//
				SqlDataAdapter sqlDTA = new SqlDataAdapter(sqlComm);
				DataTable dt = new DataTable();
				sqlDTA.Fill(dt);
				return dt;
			}
			catch (SqlException ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
		        throw ex;
			}
		    finally
		    {
		        if (sqlComm != null) sqlComm.Dispose();
		        if (con != null) con.Close();
		    }
		}

		/// <summary>
		/// Get DataTable với table class.
		/// </summary>
		/// <param name="ID">ID</param>
		/// <returns></returns>
		public static DataSet getDataSet_My(int key_ID)
		{
		    SqlConnection con = new AccessDB().get_Conn();
			SqlCommand sqlComm = new SqlCommand(st_ThongTinGia_ChiTiet_SelectByID, con);
			sqlComm.CommandType = CommandType.StoredProcedure;
			try
			{
		        con.Open();
				//
				sqlComm.Parameters.Add("@ID", SqlDbType.Int).Value = key_ID;
				//
				SqlDataAdapter sqlDTA = new SqlDataAdapter(sqlComm);
				DataSet ds = new DataSet();
				sqlDTA.Fill(ds);
				return ds;
			}
			catch (SqlException ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
		        throw ex;
			}
		    finally
		    {
		        if (sqlComm != null) sqlComm.Dispose();
		        if (con != null) con.Close();
		    }
		}

	    public static int count_With_ID_ThongTinGia(int ID_ThongTinGia)
	    {
	        SqlConnection con = new AccessDB().get_Conn();
	        SqlCommand sqlComm = new SqlCommand("st_ThongTinGia_ChiTiet_CountBy_ID_ThongTinGia", con);
	        sqlComm.CommandType = CommandType.StoredProcedure;
	        //
	        sqlComm.Parameters.Add("@ID_ThongTinGia", SqlDbType.Int).Value = ID_ThongTinGia;
	        try
	        {
	            con.Open();
	            return (int)sqlComm.ExecuteScalar();
	        }
	        catch (SqlException ex)
	        {
	            new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
	            throw ex;
	        }
	        finally
	        {
	            if (sqlComm != null) sqlComm.Dispose();
	            if (con != null) con.Close();
	        }
	    }
		public static DataTable getDataTable_With_ID_ThongTinGia(int ID_ThongTinGia,bool Hidden)
		{
		    return getDataSet_With_ID_ThongTinGia(ID_ThongTinGia,Hidden).Tables[0];
		}

		public static DataSet getDataSet_With_ID_ThongTinGia(int ID_ThongTinGia,bool Hidden)
		{
		    SqlConnection con = new AccessDB().get_Conn();
		    SqlCommand sqlComm = new SqlCommand("st_ThongTinGia_ChiTiet_SelectByID_ThongTinGia", con);
		    sqlComm.CommandType = CommandType.StoredProcedure;
		    //
		    sqlComm.Parameters.Add("@ID_ThongTinGia", SqlDbType.Int).Value = ID_ThongTinGia;
		    sqlComm.Parameters.Add("@Hidden", SqlDbType.Bit).Value = Hidden;
		    //
			try
			{
		        con.Open();
				SqlDataAdapter sqlDTA = new SqlDataAdapter(sqlComm);
				DataSet ds = new DataSet();
				sqlDTA.Fill(ds);
				return ds;
			}
			catch (SqlException ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
				throw ex;
			}
		    finally
		    {
		        if (sqlComm != null) sqlComm.Dispose();
		        if (con != null) con.Close();
		    }
		}

		public static DataTable getDataTable_With_ID_ThongTinGia(int ID_ThongTinGia)
		{
		    return getDataSet_With_ID_ThongTinGia(ID_ThongTinGia).Tables[0];
		}

		public static DataSet getDataSet_With_ID_ThongTinGia(int ID_ThongTinGia)
		{
		    SqlConnection con = new AccessDB().get_Conn();
		    SqlCommand sqlComm = new SqlCommand("st_ThongTinGia_ChiTiet_SelectByID_ThongTinGia_All",con);
		    sqlComm.CommandType = CommandType.StoredProcedure;
		    //
		    sqlComm.Parameters.Add("@ID_ThongTinGia", SqlDbType.Int).Value = ID_ThongTinGia;
		    //
			try
			{
		        con.Open();
				SqlDataAdapter sqlDTA = new SqlDataAdapter(sqlComm);
				DataSet ds = new DataSet();
				sqlDTA.Fill(ds);
				return ds;
			}
			catch (SqlException ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
				return null;
			}
		    finally
		    {
		        if (sqlComm != null) sqlComm.Dispose();
		        if (con != null) con.Close();
		    }
		}

        /// <summary>
        /// Count record by LoaiTin.
        /// </summary>
        /// <param name="LoaiTin"></param>
        /// <param name="Hidden"></param>
        /// <returns></returns>
        public static int countByID_ThongTinGia(int ID_ThongTinGia,bool Hidden)
        {
            SqlConnection con = new AccessDB().get_Conn();
            SqlCommand sqlComm = new SqlCommand("st_ThongTinGia_ChiTiet_CountByID_ThongTinGia", con);
            sqlComm.CommandType = CommandType.StoredProcedure;
            //
            sqlComm.Parameters.Add("@ID_ThongTinGia", SqlDbType.NVarChar).Value = ID_ThongTinGia;
            sqlComm.Parameters.Add("@Hidden", SqlDbType.Bit).Value = Hidden;
            try
            {
                con.Open();
                return (int)sqlComm.ExecuteScalar();
            }
            catch (SqlException ex)
            {
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
		        throw ex;
            }
		    finally
		    {
		        if (sqlComm != null) sqlComm.Dispose();
		        if (con != null) con.Close();
		    }
        }
		/// <summary>
		/// Thực hiện SQL dữ liệu.
		/// </summary>
		/// <returns></returns>
		public static bool doSQL(string sSQL)
		{
            SqlConnection con = new AccessDB().get_Conn();
            SqlCommand sqlComm = new SqlCommand("st_processSQL", con);
            sqlComm.CommandType = CommandType.StoredProcedure;
            sqlComm.Parameters.Add("@sSQL", SqlDbType.NVarChar).Value = sSQL;
			try
			{
                con.Open();
				sqlComm.ExecuteNonQuery();
				return true;
			}
			catch (SqlException  ex)
			{
		        throw ex;
			}
		    finally
		    {
		        if (sqlComm != null) con.Dispose();
		        if (con != null) con.Close();
		    }
		}
		/// <summary>
		/// Thực hiện Insert dữ liệu.
		/// </summary>
		/// <returns></returns>
		public int doInsert()
		{
        SqlConnection con = new AccessDB().get_Conn();
		SqlCommand sqlComm = new SqlCommand(st_ThongTinGia_ChiTiet_Insert,con);
        sqlComm.CommandType = CommandType.StoredProcedure;
        try
        {
				//
			    sqlComm.Parameters.Add("@ID_ThongTinGia", SqlDbType.Int).Value = ID_ThongTinGia;
				//ID_LoaiHinhDoanhNghiep
				if(ID_LoaiHinhDoanhNghiep!=null)
				    sqlComm.Parameters.Add("@ID_LoaiHinhDoanhNghiep", SqlDbType.NVarChar).Value = ID_LoaiHinhDoanhNghiep;
				else
				    sqlComm.Parameters.Add("@ID_LoaiHinhDoanhNghiep", SqlDbType.NVarChar).Value = DBNull.Value;
			    sqlComm.Parameters.Add("@DonGia", SqlDbType.Float).Value = DonGia;
			    sqlComm.Parameters.Add("@ThueGTGT", SqlDbType.Float).Value = ThueGTGT;
			    sqlComm.Parameters.Add("@Thue_1", SqlDbType.Float).Value = Thue_1;
			    sqlComm.Parameters.Add("@Thue_2", SqlDbType.Float).Value = Thue_2;
			    sqlComm.Parameters.Add("@Thue_3", SqlDbType.Float).Value = Thue_3;
			    sqlComm.Parameters.Add("@Phi_1", SqlDbType.Float).Value = Phi_1;
			    sqlComm.Parameters.Add("@Phi_2", SqlDbType.Float).Value = Phi_2;
			    sqlComm.Parameters.Add("@Phi_3", SqlDbType.Float).Value = Phi_3;
			    sqlComm.Parameters.Add("@Hidden", SqlDbType.Bit).Value = Hidden;
                con.Open();
				sqlComm.ExecuteNonQuery();
                ID = getMaxIdAuto();
				return 1;
			}
			catch (SqlException  ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
				throw ex;
			}
		    finally
		    {
		        if (sqlComm != null) con.Dispose();
		        if (con != null) con.Close();
		    }
		}
		/// <summary>
		/// Thực hiện update dữ liệu.
		/// </summary>
		/// <returns></returns>
		public int doUpdate()
		{
		    SqlConnection con = new AccessDB().get_Conn();
			SqlCommand sqlComm = new SqlCommand(st_ThongTinGia_ChiTiet_Update,con);
			sqlComm.CommandType = CommandType.StoredProcedure;
			try
			{
		        con.Open();
				//ID_find
				sqlComm.Parameters.Add("@ID_find", SqlDbType.Int).Value = ID_find;
			    sqlComm.Parameters.Add("@ID_ThongTinGia", SqlDbType.Int).Value = ID_ThongTinGia;
				//ID_LoaiHinhDoanhNghiep
				if(ID_LoaiHinhDoanhNghiep!=null)
				    sqlComm.Parameters.Add("@ID_LoaiHinhDoanhNghiep", SqlDbType.NVarChar).Value = ID_LoaiHinhDoanhNghiep;
				else
				    sqlComm.Parameters.Add("@ID_LoaiHinhDoanhNghiep", SqlDbType.NVarChar).Value = DBNull.Value;
			    sqlComm.Parameters.Add("@DonGia", SqlDbType.Float).Value = DonGia;
			    sqlComm.Parameters.Add("@ThueGTGT", SqlDbType.Float).Value = ThueGTGT;
			    sqlComm.Parameters.Add("@Thue_1", SqlDbType.Float).Value = Thue_1;
			    sqlComm.Parameters.Add("@Thue_2", SqlDbType.Float).Value = Thue_2;
			    sqlComm.Parameters.Add("@Thue_3", SqlDbType.Float).Value = Thue_3;
			    sqlComm.Parameters.Add("@Phi_1", SqlDbType.Float).Value = Phi_1;
			    sqlComm.Parameters.Add("@Phi_2", SqlDbType.Float).Value = Phi_2;
			    sqlComm.Parameters.Add("@Phi_3", SqlDbType.Float).Value = Phi_3;
				int up= sqlComm.ExecuteNonQuery();
				ID=ID_find;
				return up;
			}
			catch (SqlException  ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
				throw ex;
			}
		    finally
		    {
		        if (sqlComm != null) con.Dispose();
		        if (con != null) con.Close();
		    }
		}
		/// <summary>
		/// Thực hiện update dữ liệu.
		/// </summary>
		/// <returns></returns>
		public int doUpdate_ALL()
		{
		    SqlConnection con = new AccessDB().get_Conn();
			SqlCommand sqlComm = new SqlCommand(st_ThongTinGia_ChiTiet_Update_ALL,con);
			sqlComm.CommandType = CommandType.StoredProcedure;
			try
			{
		        con.Open();
				//ID_find
				sqlComm.Parameters.Add("@ID_find", SqlDbType.Int).Value = ID_find;
				//ID_ThongTinGia
				sqlComm.Parameters.Add("@ID_ThongTinGia", SqlDbType.Int).Value = ID_ThongTinGia;
				//ID_LoaiHinhDoanhNghiep
				sqlComm.Parameters.Add("@ID_LoaiHinhDoanhNghiep", SqlDbType.NVarChar).Value = ID_LoaiHinhDoanhNghiep;
				//DonGia
				sqlComm.Parameters.Add("@DonGia", SqlDbType.Float).Value = DonGia;
				//ThueGTGT
				sqlComm.Parameters.Add("@ThueGTGT", SqlDbType.Float).Value = ThueGTGT;
				//Thue_1
				sqlComm.Parameters.Add("@Thue_1", SqlDbType.Float).Value = Thue_1;
				//Thue_2
				sqlComm.Parameters.Add("@Thue_2", SqlDbType.Float).Value = Thue_2;
				//Thue_3
				sqlComm.Parameters.Add("@Thue_3", SqlDbType.Float).Value = Thue_3;
				//Phi_1
				sqlComm.Parameters.Add("@Phi_1", SqlDbType.Float).Value = Phi_1;
				//Phi_2
				sqlComm.Parameters.Add("@Phi_2", SqlDbType.Float).Value = Phi_2;
				//Phi_3
				sqlComm.Parameters.Add("@Phi_3", SqlDbType.Float).Value = Phi_3;
				//Hidden
				sqlComm.Parameters.Add("@Hidden", SqlDbType.Bit).Value = Hidden;
				int up = sqlComm.ExecuteNonQuery();
				ID=ID_find;
				return up;
			}
			catch (SqlException  ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
				throw ex;
			}
		    finally
		    {
		        if (sqlComm != null) con.Dispose();
		        if (con != null) con.Close();
		    }
		}
		/// <summary>
		/// Thực hiện update dữ liệu.
		/// </summary>
		/// <returns></returns>
		public static int doUpdate_KEY(string Key_ID_Old,string Key_ID_New)
		{
		    SqlConnection con = new AccessDB().get_Conn();
		    string sql = "Update tbThongTinGia_ChiTiet Set ID=@ID_New Where ID=@ID_old";
			SqlCommand sqlComm = new SqlCommand(sql,con);
			sqlComm.CommandType = CommandType.Text;
			try
			{
			    sqlComm.Parameters.Add("@ID_New", SqlDbType.Int).Value = Key_ID_New;
			    sqlComm.Parameters.Add("@ID_old", SqlDbType.Int).Value = Key_ID_Old;
		        con.Open();
		        sqlComm.ExecuteNonQuery();
		        return 1;
		    }
		    catch (SqlException  ex)
		    {
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
		        throw ex;
		    }
		    finally
		    {
		        if (sqlComm != null) con.Dispose();
		        if (con != null) con.Close();
		    }
		}
		/// <summary>
		/// Thực hiện update dữ liệu.
		/// </summary>
		/// <returns></returns>
		public int doUpdateHidden()
		{
		    SqlConnection con = new AccessDB().get_Conn();
			SqlCommand sqlComm = new SqlCommand(st_ThongTinGia_ChiTiet_Update_Hidden, con);
			sqlComm.CommandType = CommandType.StoredProcedure;
			try
			{
				//ID
				sqlComm.Parameters.Add("@ID", SqlDbType.Int).Value = ID_find;
				sqlComm.Parameters.Add("@Hidden", SqlDbType.Bit).Value = Hidden;
		        con.Open();
				sqlComm.ExecuteNonQuery();
				return 1;
			}
			catch (SqlException  ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
				return -1;
			}
		    finally
		    {
		        if (sqlComm != null) con.Dispose();
		        if (con != null) con.Close();
		    }
		}
		/// <summary>
		/// Thực hiện xóa dữ liệu.
		/// </summary>
		/// <returns></returns>
		public int doDelete()
		{
		    SqlConnection con = new AccessDB().get_Conn();
			SqlCommand sqlComm = new SqlCommand(st_ThongTinGia_ChiTiet_Delete, con);
			sqlComm.CommandType = CommandType.StoredProcedure;
			try
			{
				sqlComm.Parameters.Add("@ID", SqlDbType.Int).Value = ID_find ;
				//
		        con.Open();
		    	sqlComm.ExecuteNonQuery() ;
				return 1;
			}
			catch (SqlException ex)
			{
		        new MyLog.Log_DB().setLog(TABLE_NAME, ex.Message);
				throw ex;
			}
		    finally
		    {
		        if (sqlComm != null) con.Dispose();
		        if (con != null) con.Close();
		    }
		}

		/// <summary>
		/// Conver sang Object.
		/// </summary>
		/// <returns></returns>
		public static Cls_ThongTinGia_ChiTiet converDataRow_To_Object(DataRow dr)
		{
			Cls_ThongTinGia_ChiTiet _Object = new Cls_ThongTinGia_ChiTiet();
		    if( dr[fn_ID]!= DBNull.Value )
		        _Object.ID =  (int)dr[fn_ID];
		    if( dr[fn_ID_ThongTinGia]!= DBNull.Value )
		        _Object.ID_ThongTinGia =  (int)dr[fn_ID_ThongTinGia];
		    if( dr[fn_ID_LoaiHinhDoanhNghiep]!= DBNull.Value )
		        _Object.ID_LoaiHinhDoanhNghiep =  (string)dr[fn_ID_LoaiHinhDoanhNghiep];
		    if( dr[fn_DonGia]!= DBNull.Value )
		        _Object.DonGia =  (double)dr[fn_DonGia];
		    if( dr[fn_ThueGTGT]!= DBNull.Value )
		        _Object.ThueGTGT =  (double)dr[fn_ThueGTGT];
		    if( dr[fn_Thue_1]!= DBNull.Value )
		        _Object.Thue_1 =  (double)dr[fn_Thue_1];
		    if( dr[fn_Thue_2]!= DBNull.Value )
		        _Object.Thue_2 =  (double)dr[fn_Thue_2];
		    if( dr[fn_Thue_3]!= DBNull.Value )
		        _Object.Thue_3 =  (double)dr[fn_Thue_3];
		    if( dr[fn_Phi_1]!= DBNull.Value )
		        _Object.Phi_1 =  (double)dr[fn_Phi_1];
		    if( dr[fn_Phi_2]!= DBNull.Value )
		        _Object.Phi_2 =  (double)dr[fn_Phi_2];
		    if( dr[fn_Phi_3]!= DBNull.Value )
		        _Object.Phi_3 =  (double)dr[fn_Phi_3];
		    if( dr[fn_Hidden]!= DBNull.Value )
		        _Object.Hidden =  (bool)dr[fn_Hidden];
		    //============
		    return _Object;
		}

		/// <summary>
		/// Get DataTable với table class.
		/// </summary>
		/// <param name="ID">ID</param>
		/// <returns></returns>
		public static Cls_ThongTinGia_ChiTiet getOject_Key(int key_ID)
		{
		    DataTable dt = getDataTable_My(key_ID);
		    //==========================
		    if (dt.Rows.Count > 0)
		        return converDataRow_To_Object(dt.Rows[0]);
		    else
		        return null;
		}

		/// <summary>
		/// Get Array object class.
		/// </summary>
		/// <returns></returns>
		public static Cls_ThongTinGia_ChiTiet[] getArrayObject(DataTable dt)
		{
		    if (dt.Rows.Count == 0) return null;
		    //
		    Cls_ThongTinGia_ChiTiet[] arr = new Cls_ThongTinGia_ChiTiet[dt.Rows.Count];
		    int i = 0;
		    foreach (DataRow dr in dt.Rows)
		    {
		    
		        arr[i] = converDataRow_To_Object( dr  );
		        i++;
		    }
		    return arr;
		}

		/// <summary>
		/// Get Array object class.
		/// </summary>
		/// <returns></returns>
		public static Cls_ThongTinGia_ChiTiet[] getArrayObject()
		{
		    return getArrayObject( getDataTable_My() );
		}

	}

}
